//
//  ZYTableFormView.m
//  Tourism
//
//  Created by 张亚 on 16/1/26.
//  Copyright © 2016年 zhangya. All rights reserved.
//

#import "ZYTableFormView.h"

@implementation ZYTableFormView


/*
在View第一次显示到屏幕的时候会调用一次
 */
- (void)drawRect:(CGRect)rect {
    //1、获取画板
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //2、画矩形
    CGContextAddRect(context, CGRectMake(10, 40, SCREEN_WIDTH - 20, self.bounds.size.height - 41));
    
    //3、绘制图形
    CGContextStrokePath(context);
    
    //填表格
    CGContextMoveToPoint(context, 10, 80);
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, 80);
    CGContextStrokePath(context);
    
    CGContextMoveToPoint(context, 10, 120);
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, 120);
    CGContextStrokePath(context);
    
    CGContextMoveToPoint(context, 10, 160);
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, 160);
    CGContextStrokePath(context);
    
    CGContextMoveToPoint(context, 10, 200);
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, 200);
    CGContextStrokePath(context);
    
    //时间
    CGContextMoveToPoint(context, self.bounds.size.width - 310, 80);
    CGContextAddLineToPoint(context, self.bounds.size.width - 310, 240);
    CGContextStrokePath(context);
    //血压
    CGContextMoveToPoint(context, self.bounds.size.width - 250, 80);
    CGContextAddLineToPoint(context, self.bounds.size.width - 250, 240);
    CGContextStrokePath(context);
    //血糖
    CGContextMoveToPoint(context, self.bounds.size.width - 180, 80);
    CGContextAddLineToPoint(context, self.bounds.size.width - 180, 240);
    CGContextStrokePath(context);
    //体重
    CGContextMoveToPoint(context, self.bounds.size.width - 100, 80);
    CGContextAddLineToPoint(context, self.bounds.size.width - 100, 240);
    CGContextStrokePath(context);
    //记步
//    CGContextMoveToPoint(context, self.bounds.size.width - 70, 40);
//    CGContextAddLineToPoint(context, self.bounds.size.width - 70, 240);
//    CGContextStrokePath(context);
    
    
    //画“历史记录”
    CGRect cubeRect = CGRectMake(10, 0, SCREEN_WIDTH - 20, 40);
    CGContextAddRect(context, cubeRect);
    [ZYSuitColor(73, 207, 180) setFill];
    
    CGContextFillPath(context);
    NSString * str = @"                 历史记录";
    NSMutableDictionary * titleDict = [NSMutableDictionary dictionary];
    titleDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    titleDict[NSFontAttributeName] = [UIFont systemFontOfSize:30];
    [str drawInRect:cubeRect withAttributes:titleDict];
    
    //画“时间”
    CGRect timeRect = CGRectMake(10, 40, self.bounds.size.width - 320, 39);
    CGContextAddRect(context, timeRect);
    CGContextStrokePath(context);
    NSString * timeStr = @"时间";
    NSMutableDictionary * timeDict = [NSMutableDictionary dictionary];
    timeDict[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [timeStr drawInRect:timeRect withAttributes:timeDict];
    
    //画“血压”
    CGRect timeRect1 = CGRectMake(self.bounds.size.width - 310, 40, 60, 39);
    CGContextAddRect(context, timeRect1);
    CGContextStrokePath(context);
    NSString * timeStr1 = @"血压";
    NSMutableDictionary * timeDict1 = [NSMutableDictionary dictionary];
    timeDict1[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [timeStr1 drawInRect:timeRect1 withAttributes:timeDict1];
    
    //画“血糖”
    CGRect timeRect2 = CGRectMake(self.bounds.size.width - 250, 40, 70, 39);
    CGContextAddRect(context, timeRect2);
    CGContextStrokePath(context);
    NSString * timeStr2 = @"血糖";
    NSMutableDictionary * timeDict2 = [NSMutableDictionary dictionary];
    timeDict2[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [timeStr2 drawInRect:timeRect2 withAttributes:timeDict2];
    
    //画“体重”
    CGRect timeRect3 = CGRectMake(self.bounds.size.width - 180, 40, 80, 39);
    CGContextAddRect(context, timeRect3);
    CGContextStrokePath(context);
    NSString * timeStr3 = @"体重";
    NSMutableDictionary * timeDict3 = [NSMutableDictionary dictionary];
    timeDict3[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [timeStr3 drawInRect:timeRect3 withAttributes:timeDict3];
    
    //画“记步”
    CGRect timeRect4 = CGRectMake(self.bounds.size.width - 100, 40, 90, 39);
    CGContextAddRect(context, timeRect4);
    CGContextStrokePath(context);
    NSString * timeStr4 = @"记布";
    NSMutableDictionary * timeDict4 = [NSMutableDictionary dictionary];
    timeDict4[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    [timeStr4 drawInRect:timeRect4 withAttributes:timeDict4];
    
//    [self drawSqureShape];
}



























//第一种方案是一条条划线画出四边形（但是我想直接画出四边形 所以不采用这种方法）
- (void) drawSqureShape{
    //1、获取画板（上下文）
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //2、画图形
    CGContextMoveToPoint(context, 10, 10);
    //添加线段
    CGContextAddLineToPoint(context, 10, self.bounds.size.height - 10);
    
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, self.bounds.size.height - 10);
    CGContextAddLineToPoint(context, SCREEN_WIDTH - 10, 10);
    //关闭图形（也就是起点和终点连接）
    CGContextClosePath(context);
    
    //3、绘制图形（显示画内容）
    CGContextStrokePath(context);
    

}


@end
